import { SelectSort, InsertSort, MergeSort } from "./sorting.js"

class SortHelper {
    static isSorted(sequence) {
        for (let i = 1; i < sequence.length; i++) {
            if (sequence[i - 1] > sequence[i]) {
                return false
            }
        }
        return true
    }

    static sortTest(sortname, sequence) {
        let start = new Date().getTime()
        if (sortname == "选择排序") {
            SelectSort.sort(sequence)
        }else if (sortname == "插入排序") {
            InsertSort.sort(sequence)
        }else if (sortname == "归并排序") {
            MergeSort.sort(sequence)
        }
        let end = new Date().getTime()

        if(this.isSorted(sequence)) {
            console.log(`${sortname} n = ${sequence.length} 消耗 ${end - start} ms`)
        }else {
            console.log(`${sortname} 排序失败`)
        }
    }
}

export {SortHelper}